package com.thyc.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.thyc.entity.LimitValue;
import com.thyc.entity.SourceData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * 源数据表(SourceData)表数据库访问层
 *
 * @author moer
 * @since 2021-01-19 15:27:12
 */
public interface SourceDataDao extends BaseMapper<SourceData> {

    @Select("select data_two from jk_source_data where sensor_model = 'JMDL-6610RD' and add_time = (SELECT MAX(add_time) FROM jk_source_data WHERE sensor_model = 'JMDL-6610RD')")
    String findLastTimeFlip();

    @Select("select data_one from jk_source_data where model_num = #{modelNum} and passageway = #{passageway} and add_time = (SELECT MAX(add_time) FROM jk_source_data WHERE model_num = #{modelNum} and passageway = #{passageway})")
    BigDecimal findLastTimeStrainGauge(@Param("modelNum") String modelNum, @Param("passageway") String passageway);

    @Update("truncate table jk_source_data")
    void truncate();

    @Select("select add_time,passageway,sensor_model,sensor_num,data_one,unit_one from jk_source_data where sensor_model = #{sensorModel} into outfile 'c:/sourcedata/${today}(${sensorModel}).cvs'")
    void backUp(String today,String sensorModel);

    @Select("select passageway as channelNum,MAX(data_one) as maxV,MIN(data_one) as minV from jk_source_data GROUP BY passageway")
    List<LimitValue> selectMaxAndMinValue();

}